//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XPanel.h>
///	@path	~/src/gui/xgui/
///	@date	2008/10/30
///	@brief	.

#pragma once

#include "xeres.h"

#include "gui/IGuiControl.h"
#include "gui/style/style.h"
#include "gui/style/ext_style.h"
#include "gui/style/StyleText.h"
#include "gui/image/IBitmap.h"
#include "gui/xgui/XForm.h"
#include "gui/xgui/XCtrls.h"

namespace xeres {

	/*! 
		\class	XPanel
		\brief
	*/
	class XPanel : public XForm , public GuiSyleComp<CGuiStyle>
	{
	public:

		/// \ctor
		XPanel( void );

		/// \ctor
		XPanel( const Rect<int>& placement );

		/// \ctor
		XPanel( const Pair<int>& size );

		/// \ctor
		XPanel( RefWeak<IBitmap> background );

		/// \dtor
		virtual ~XPanel( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XPanel , XForm );

	public:

		/// \name XGui Component Attributes
		//@{

		/// \brief	Get text style.
		RefWeak<CTextStyle> GetStyle( void );

		/// \brief	Set size of component.
		virtual bool SetSize( const Pair<int>& size );

		/// \breif	Set edge size.
		bool SetEdgeSize( const Pair<int>& edge );
		
		/// \brief	Get edge size.
		Pair<int> GetEdgeSize( void ) const;

		/// \brief	Set background.
		void SetBackground( RefWeak<IBitmap> background );

		/// \brief	Set background.
		void SetBackground( RefWeak<IBitmap> background , const Pair<int>& edge );

		/// \brief	Get background.
		RefWeak<IBitmap> GetBackground( void );

		//@}

		/// \name Message Passing
		//@{

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		/// \brief	Call when control is about to enable or disable.
		virtual void OnEnable( bool enable );

		/// \brief	Call when focus is about to change.
		virtual void OnFocus( bool focusing );

		/// \brief	Call when mouse over control.
		virtual void OnMouseOver( bool hovering );

		//@}

		/// \brief	Draw background.
		virtual void OnDrawBackground( Composition& composition );

	private:

		/// \brief	Change style call.
		void ChangeStyle( void );

		// @data
		Ref<IBitmap>			m_background;
		Pair<int>				m_edgeSize;
	};

	/*! 
		\class	XScrollPanel
		\brief
	*/
	class XScrollPanel : public XPanel
	{
	public:

		/// \ctor
		XScrollPanel( void );

		/// \ctor
		XScrollPanel( const Rect<int>& placement );

		/// \ctor
		XScrollPanel( const Pair<int>& size );

		/// \ctor
		XScrollPanel( RefWeak<IBitmap> background );

		/// \dtor
		virtual ~XScrollPanel( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XScrollPanel , XPanel );

	public:

		/// \brief	Add child component.
		virtual bool AddChild( RefWeak<IGuiComp> comp );

		/// \brief	Del child component.
		virtual bool DelChild( RefWeak<IGuiComp> comp );

		/// \brief	Get child by index.
		virtual RefWeak<IGuiComp> GetChild( int index );

		/// \brief	Set size of component.
		virtual bool SetSize( const Pair<int>& size );

		/// \brief	Set client panel.
		virtual bool SetClientPanel( RefWeak<XPanel> panel );

		/// \brief	Get client panel.
		virtual RefWeak<XPanel> GetClientPanel( void );

	private:
		
		/// \brief	Initialize form.
		void InitForm( void );

		/// \brief	On vertical scroll.
		void OnVerticalScroll( float pos );

		/// \brief	On horizontal scroll.
		void OnHorizontalScroll( float pos );

		//@ data
		Ref<XPanel>					m_clientPanel;

		Ref<XScrollBarVertical>		m_verticalScroll;
		Ref<XScrollBarHorizontal>	m_horizontalScroll;
	};

 } // namespace xeres
